package com.gadgets.cm01.role.controller.impl;

import com.gadgets.cm01.common.GadgetsCm01Constant;
import com.gadgets.cm01.role.controller.IRoleUserAllocationController;
import com.gadgets.cm01.role.dto.UserRoleAllocationDTO;
import com.gadgets.cm01.role.service.IRoleUserAllocationService;
import com.gadgets.framework.annotation.RoleAuthCheck;
import com.gadgets.framework.common.constant.GadgetsConstant;
import com.gadgets.framework.common.dto.HttpBaseResp;
import com.gadgets.framework.common.exception.GadgetsServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020-10-15
 * 
 */
@RestController
@RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/roleUserAllocation")
public class RoleUserAllocationControllerImpl implements IRoleUserAllocationController {

    @Autowired
    @Qualifier(value = "roleUserAllocationServiceImpl")
    private IRoleUserAllocationService roleUserAllocationService;

    /**
     * 分配/收回角色给指定用户
     *
     * @param request       请求对象
     * @param response      应答对象
     * @param allocationDTO 执行信息
     *
     * @return 执行结果
     *
     * @throws GadgetsServiceException 异常信息
     */
    @RoleAuthCheck(userType = {GadgetsConstant.USER_TYPE.SYS_MANAGER})
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/roleUserAllocation.do")
    @Override
    public HttpBaseResp<Object> roleuserAllocation(HttpServletRequest request, HttpServletResponse response, UserRoleAllocationDTO allocationDTO) throws GadgetsServiceException {
        if(GadgetsCm01Constant.ROLE_AUTH_OPER_TYPE.ALLOCATION.equals(allocationDTO.getOperType())){
            roleUserAllocationService.allocationRole(allocationDTO);
        }else {
            roleUserAllocationService.reAllocationRole(allocationDTO);
        }
        return new HttpBaseResp<>();
    }
    
}
